package com.coreJava.test02;

import java.util.concurrent.Semaphore;

/**
 * 作者: LCG
 * 日期: 2019/9/3 17:21
 * 描述:
 */
public class MySymphRunable implements Runnable {

    private Semaphore semaphore;

    public MySymphRunable(Semaphore semaphore) {
        this.semaphore = semaphore;
    }

    @Override
    public void run() {

        try {
            semaphore.acquire();

            for (int i=0;i<10;i++){
                Thread.sleep(500);
                System.out.println("-----当前线程--"+Thread.currentThread().getName()+"---"+i);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            semaphore.release();
        }


    }
}
